package com.xuchen.zhenyang.controller;


import com.xuchen.zhenyang.base.Result;
import com.xuchen.zhenyang.controller.base.BaseController;
import com.xuchen.zhenyang.entity.CustomerText;
import com.xuchen.zhenyang.service.CustomerTextService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/server")
@CrossOrigin
@Slf4j
public class ServerController extends BaseController {

    @Autowired
    CustomerTextService customerTextService;

    @GetMapping("getText")
    @ResponseBody
    Result getText(String id) {
        CustomerText customerText = customerTextService.selectById(id);
        if (customerText == null){
            return Result.fail();
        }
        customerText.setRequestCount(customerText.getRequestCount()+1);
        customerTextService.updateById(customerText);
        CustomerText result = new CustomerText();
        result.setTitle(customerText.getTitle());
        result.setContent(customerText.getContent());
        return Result.success(result);
    }
}

